package cn.wuwenyao.patch.generator;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.wuwenyao.patch.generator.entity.PatchInfo;
import cn.wuwenyao.patch.generator.entity.ProjectInfo;

/***
 * 生成补丁-执行器
 * 
 * @author wwy
 *
 */
public class GeneratePatchExecutor {
	
	private static List<PatchGenerator> generators = new ArrayList<>();
	
	private static final Logger LOG = LoggerFactory.getLogger(GeneratePatchExecutor.class);
	
	static {
		// 添加生成器
		generators.add(new SvnPatchGenerator());
		generators.add(new GitPatchGenerator());
	}
	
	public static void execute(ProjectInfo projectInfo, PatchInfo patchInfo) {
		for (PatchGenerator patchGenerator : generators) {
			if (patchGenerator.support(projectInfo.getVersionManagerType())) {
				try {
					patchGenerator.generatePatch(projectInfo, patchInfo);
				} catch (Exception e) {
					e.printStackTrace();
					return;
				}
				LOG.info("生成补丁成功");
				break;
			}
		}
	}
	
}
